//
//  AFHttpTool.m
//  RENTVISITOR
//
//  Created by wonder on 2017/8/28.
//  Copyright © 2017年 UNN. All rights reserved.
//

#import "AFHttpTool.h"

@implementation AFHttpTool


+(void) requestWihtUrl : (NSString *)url
                   params:(NSDictionary *)params
                  success:(void (^)(id response))success
                  failure:(void (^)(NSError *err))failure {
    
    [SVProgressHUD show];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
   
    manager.responseSerializer = [AFJSONResponseSerializer serializer];//设置返回数据为json
//    if ([url isEqualToString:@"http://api2.zuke.com/member/lease/fang"]) {
//         manager.requestSerializer = [AFJSONRequestSerializer serializer];
//    }else {
            manager.requestSerializer = [AFHTTPRequestSerializer serializer];// 请求
//    }

    manager.requestSerializer.stringEncoding = NSUTF8StringEncoding;
    manager.requestSerializer.timeoutInterval= 60;
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithArray:@[@"application/json",
                                                                              @"text/html",
                                                                              @"text/json",
                                                                              @"text/plain",
                                                                              @"text/javascript",
                                                                              @"text/xml",
                                                                              @"image/*"]];
    
    [manager POST:url parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        [SVProgressHUD dismiss];
        
        success(responseObject);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
       
            
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
        [SVProgressHUD dismissWithDelay:2.0f];
        failure(error);
        
    }];

    
}

@end
